package com.shruijin.wy.thread.cas.lock;

import com.shruijin.wy.thread.anno.SimpleThreadAnno;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.atomic.AtomicBoolean;

public class AtomaticLock {

    Logger LOGGER  = LoggerFactory.getLogger(this.getClass());

    private AtomicBoolean locked = new AtomicBoolean(false);

    public boolean getLock(){
//        if (!locked.get()){
//            locked.set(true);
//            return true;
//        }
//        return false;

        LOGGER.info("{} get lock!",Thread.currentThread().getName());
        return locked.compareAndSet(false,true);
    }

}
